import store from "@/store";
// 获取旋转角度
export function GetRotale(Dom) {
  var st = window.getComputedStyle(Dom, null);  
  // console.log("st",st);
  var tr =
    st.getPropertyValue("-webkit-transform") ||
    st.getPropertyValue("-moz-transform") ||
    st.getPropertyValue("-ms-transform") ||
    st.getPropertyValue("-o-transform") ||
    st.getPropertyValue("transform") ||
    "FAIL";
  // With rotate(30deg)...
  // matrix(0.866025, 0.5, -0.5, 0.866025, 0px, 0px)
  // console.log("Matrix: " + tr);

  // rotation matrix - http://en.wikipedia.org/wiki/Rotation_matrix
  var values = tr.split("(")[1].split(")")[0].split(",");
  console.log("矩阵数组",values);

  var a = values[0];
  var b = values[1];
  var c = values[2];
  var d = values[3];
  getmatrix(a, b, c, d);
  // var scale = Math.sqrt(a * a + b * b); //缩放
  // console.log("Scale: " + scale);
  // arc sin, convert from radians to degrees, round
  // var sin = b / scale;
  // next line works for 30deg but not 130deg (returns 50);  //正负180度
  // var angle = Math.round(Math.asin(sin) * (180/Math.PI));
  // console.log("a", Math.round((180 * Math.acos(c)) / Math.PI) );
  // var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
  // console.log("Rotate: " + angle + "deg");
}


// 360度
function getmatrix(a, b, c, d, e, f) {
  var aa = Math.round((180 * Math.asin(a)) / Math.PI);
  var bb = Math.round((180 * Math.acos(b)) / Math.PI);
  var cc = Math.round((180 * Math.asin(c)) / Math.PI);
  var dd = Math.round((180 * Math.acos(d)) / Math.PI);
  console.log("(aa+','+bb+','+cc+','+dd)", aa + "," + bb + "," + cc + "," + dd);
  var deg = 0;
  if (aa == bb || -aa == bb) {
    deg = dd;
  } else if (-aa + bb == 180) {
    deg = 180 + cc;
  } else if (aa + bb == 180) {
    deg = 360 - cc || 360 - dd;
  }
 
  // console.log("deg>=360?0:deg;",deg>=360?0:deg);
  let angle = deg >= 360 ? 0 : deg;
  console.log("deg>=360?0:deg", angle);
 
  store.commit("PlayState/SET_ANIMATION_ROTALE", `${angle}deg`);
  //return (aa+','+bb+','+cc+','+dd);
}
